import Vue from 'vue'
import VueRouter from 'vue-router'

//解决路由命名冲突的解决方法
const routePush=VueRouter.prototype.push;
VueRouter.prototype.push=function push(location) {
    return routePush.call(this,location).catch(error=>error)
};

//异步组件加载
const Index = () => import('@/views/Index.vue');
const Login= () => import('@/views/Login/index.vue');
const Home = () => import('@/views/Home/index.vue');
const Goods = () => import("@/views/Goods/index.vue");
const Thanks = () => import('@/views/Thanks/index.vue');
const GoodsDetail = () => import("@/views/GoodsDetail/index.vue");
const User = () => import("@/views/User/index.vue");

// import Index from '@/views/Index'
// import Login from "@/views/Login/index"
// import Home from "@/views/Home/index"


Vue.use(VueRouter);

const routes = [
    {
        path:'/',
        redirect:'/home',
        name:'home',
        component:Index,
        children:[
            {
                path:'home',
                component:Home
            },
            {
                path:'goods',
                component:Goods
            },
            {
                path:'thanks',
                component:Thanks
            },
            {
                path:'goodsDetail',
                component:GoodsDetail,
                name:'goodsDetail'
            },
        ]
    },
    {
        path:'/login',
        name:'login',
        component:Login
    },
    {
        path:'/user',
        name:'user',
        component:User,
        meta:{
            ///需要守卫
            auth:true
        }
    }
];

const router = new VueRouter({
    mode:'history',//干净模式
    routes
});

export default router
